package com.lenovo.smarttraffic.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lenovo.smarttraffic.R;

public class ToastUtils {

    private static Toast mToast = null;

    public static void showToast(Context context, String text, int duration) {
        if (mToast == null) {
            mToast = Toast.makeText(context, text, duration);
        } else {
            mToast.setText(text);
            mToast.setDuration(duration);
        }

        mToast.show();
    }

    public static void showToast(Context context, String text) {
        showToast(context, text, Toast.LENGTH_SHORT);
    }

    public static void showCustomToast(Context context, String text, int duration) {
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 150);

        View view = LayoutInflater.from(context).inflate(R.layout.toast_text, null);
        TextView tv = view.findViewById(R.id.tv);
        tv.setText(text);

        toast.setView(view);
        toast.setDuration(duration);
        toast.show();
    }
}
